const express = require('express');
const { buildSchema } = require('graphql');
const { graphqlHTTP } = require('express-graphql');

const schema = buildSchema(`
  type User {
    name: String
    age: Int
  }
  type Query {
    getUser(name:String): User
    getNumArr(count: Int!): [Int]
  }
`);

const root = {
  getUser({ name }) {
    return {
      name,
      age: 18,
    };
  },
  getNumArr({ count }) {
    return new Array(count).fill(1);
  },
};

const app = express();
app.use(
  '/api/graphql',
  graphqlHTTP({
    schema,
    rootValue: root,
    graphiql: true,
  })
);

app.listen(3000, () => {
  console.log('server is running in http://localhost:3000');
});
